<template>
	<div class="main">
		<div class="title">职业意向
			<div class="line"></div>
		</div>
		<el-table class="table" :data="bigjobtypelist" :row-key="getRowKeys" :expand-row-keys="expands"
			@row-click="clickRowHandle" @expand-change="expandSelect">
			<!-- 根据后台数据进行选择渲染职业小类 -->
			<el-table-column type='expand'>
				<template v-slot:default='scope'>
					<!-- 职业小类的渲染 -->
					<el-row v-for="(item1,i1) in scope.row.detailjob" :key="i1"
						:class="['bdbottom',i1===0?'bdtop':'','vcenter','elcenter']">
						<el-col :span="8">
							<el-tag class="tag1" size="medium">{{item1.occupationSubcategory}}
								<i class="el-icon-caret-right"></i>
							</el-tag>

						</el-col>
						<el-col :span="16">
							<!-- 职业岗位的渲染 -->
							<el-row v-for="(item2,i2) in scope.row.detailjob[i1].careerPosition" :key="i2">
								<el-tooltip class="item" effect="dark" content="点击查看岗位具体内容" placement="top-start">
									<el-tag v-if="scope.row.detailjob[i1]!=''" type="success" class="tag" size="medium"
										@click="getdetailmessage(item2)">{{item2}}</el-tag>
								</el-tooltip>


							</el-row>
						</el-col>
					</el-row>
				</template>
			</el-table-column>
			<!-- 职业大类 -->
			<el-table-column prop="occupationalCategory" @click="" width="630px">
			</el-table-column>
		</el-table>
		<!-- 具体职业的模态框 -->
		<el-dialog :visible.sync="jobdialogVisible" class="modal" width="50%" append-to-body>
			<template slot="title">
				<div style="font-size: 35px;
		font-family: Noto Sans SC;color:#38b48b;font-weight: bold;">{{title}}</div>
			</template>
			<p>{{occupationalrequirements[0]}}:</p>
			<span>{{occupationalrequirements[1]}}</span>
			<span v-if="occupationalrequirements[1]==''">暂时没有数据</span>
			<p>{{jobcontent[0]}}:</p>
			<span>{{jobcontent[1]}}</span>
			<span v-if="Careerdevelopmentcases[1]==''">暂时没有数据</span>
			<p>{{Careerdevelopmentcases[0]}}:</p>
			<span>{{Careerdevelopmentcases[1]}}</span>
			<!-- <span v-if="Careerdevelopmentcases[1]!=='/n'">暂时没有数据</span> -->

			<span slot="footer" class="dialog-footer">
				<el-button @click="jobdialogVisible = false">返回</el-button>
			</span>
		</el-dialog>
	</div>

</template>
<script>
	export default ({
		data() {
			return {
				// 职业大类
				bigjobtypelist: [],
				stationlist: [],
				jobdialogVisible: false,
				occupationalrequirements: "",
				jobcontent: "",
				Careerdevelopmentcases: "",
				title: '',
				expands: [],
				getRowKeys(row) {
					return row.number
				},

			}
		},
		created() {
			this.getbigjoblist()
		},
		methods: {
			// 获取职业大类和和职业小类
			async getbigjoblist() {
				const {
					data: res
				} = await this.$axios.get(
					`${this.baseURL}/ProfessionalClassification/showAllCategory`)
				if (res.status !== 200) {
					this.$message.error('获取失败')
				}
				this.bigjobtypelist = res.data
				// console.log(this.bigjobtypelist)
				console.log(this.bigjobtypelist)
			},
			// 根据岗位获取具体岗位信息
			async getdetailmessage(mes) {
				this.title = mes + "的岗位详细描述"
				const {
					data: res
				} = await this.$axios.post(
					`${this.baseURL}/ProfessionalClassification/showWorkContentByCareerPosition?careerPosition=${mes}`
				)
				if (res.status !== 200) {
					this.$message.error('获取失败')
				}
				// this.detailjob=res.data
				this.occupationalrequirements = res.data[0].split(":")
				this.jobcontent = res.data[1].split(":")
				this.Careerdevelopmentcases = res.data[2].split(":")
				this.Careerdevelopmentcases[1] = (this.Careerdevelopmentcases[1].split("<br>")).join("")
				this.jobdialogVisible = true
				// console.log(this.Careerdevelopmentcases[1]=='/n')
			},
			async expandSelect(row, expandedRows) {
				console.log('expandedRows', expandedRows)
				console.log('row', row)
				// console.log(this.bigjobtypelist)
				// var that = this
				if (expandedRows.length) {
					this.expands = []
					if (row) {

						// 通过大类名字查询小类，但是再页面有点卡顿，需优化，本次交底时间急，来不及优化。
						const {
							data: res
						} = await this.$axios.post(
							`${this.baseURL}/ProfessionalClassification/selectOccupationSubcategoryCareerPositionByCategory?category=${row.occupationalCategory}`
						)
						if (res.status != 200) {
							this.$message.error('获取失败')
						}
						this.bigjobtypelist[row.number - 1]['detailjob'] = new Array(0);
						this.bigjobtypelist[row.number - 1]['detailjob'] = res.data;
						console.log(this.bigjobtypelist)


						this.expands.push(row.number) // 每次push进去的是每行的ID

					}

				} else {
					this.expands = [] // 默认不展开
				}
			},
			async clickRowHandle(row, column, event) {
				if (this.expands.includes(row.number)) {
					this.expands = []
				} else {
					this.expands = []
					if (row) {

						// 通过大类名字查询小类，但是再页面有点卡顿，需优化，本次交底时间急，来不及优化。
						const {
							data: res
						} = await this.$axios.post(
							`${this.baseURL}/ProfessionalClassification/selectOccupationSubcategoryCareerPositionByCategory?category=${row.occupationalCategory}`
						)
						if (res.status != 200) {
							this.$message.error('获取失败')
						}
						this.bigjobtypelist[row.number - 1]['detailjob'] = new Array(0);
						this.bigjobtypelist[row.number - 1]['detailjob'] = res.data;
						console.log(this.bigjobtypelist)


						this.expands.push(row.number) // 每次push进去的是每行的ID

					}
					// this.expands.push(row.number);
				}
			}



		}

	})
</script>
<style scoped>
	.main {
		width: 100%;

	}

	p {
		font-size: 30px;
		font-family: Noto Sans SC;
		color: #000000;
	}

	span {
		font-size: 23px;
		font-family: Noto Sans SC;
	}

	.title {
		text-align: left;
		width: 100%;
		height: 62px;
		font-size: 24px;
		font-family: Noto Sans SC;
		font-weight: 700;
		text-align: left;
		color: #333333;
		margin-top: 15px;
		margin-left: 20px;
		position: relative;
	}

	.line {
		position: absolute;
		bottom: 0px;
		width: 1025px;
		height: 2px;
		background-color: rgba(51, 170, 255, .4);
	}

	/* .news_items{
    width: 960px;
    margin: 0 auto;
    margin-bottom: 30px;
}
.imagination{
    width: 969px;
    height: 1082px;
    margin-left: 30px;
} */
	.thislabel {
		height: 50px;
		font-size: 20px;
		margin-top: 20px;
	}

	.bigjob {
		background-color: #CCCCCC
	}

	.bigoccupation {
		border-left: 1px solid #0000ff;
	}

	.el-tag {
		margin-left: 100px;

	}

	.bdtop {
		border-top: 1px solid #211610
	}

	.bdbottom {
		border-bottom: 1px solid #211610
	}

	.elcenter {
		display: flex;
		align-items: center;
	}

	.tag {
		margin: 10px;
		margin-left: 300px;
		cursor: pointer;
		font-size: 20px;
	}

	.tag1 {
		font-size: 26px;
	}

	.table {
		font-size: 22px;
	}

	.table>>>.el-table__row {
		cursor: pointer;
	}
</style>
